package com.briup.day11;

/**
 * @author lining
 * @date 2024/1/22 14:17
 */
public class TestLocalClass2 {
    public static void printNum(Operator operator,int a,int b){
        int result = operator.action(a, b);
        System.out.println(result);
    }
    public static void main(String[] args) {
        //调用printNum
        int a = 1;
        int b = 2;
        //创建该接口的实现类。实现action方法
        Operator o = new Operator() {
            @Override
            public int action(int a, int b) {
                return a * b;
            }
        };
        printNum(o,a,b);

        //加法操作：
        Operator add = new Operator() {
            @Override
            public int action(int a, int b) {
                return a + b;
            }
        };
        printNum(add,a,b);
        //创建Animal子类
        Animal animal = new Animal() {
            public void run() {
                System.out.println("表示水里游");
            }
        };
        animal.run();//输出(没有名字的)子类重写的方法
    }
}
//操作接口.实现2个数字的操作
interface Operator{
    int action(int a,int b);
}
class Animal{
    public void run(){};
}